import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
  state: {
    showNav: false, //是否显示导航栏
    activeTab: 'home', //激活的tab home:主页 service:服务 cases:案例 about:关于我们 join:计入我们 contact:联系我们
    transX: 'translateX(0px)',//nav底部线的偏移量
    headerEl:null,//header组件DOM
    serviceEl:null,//service组件DOM
    casesEl:null,//cases组件DOM
    aboutEl:null,//about组件DOM
    joinEl:null,//join组件DOM
    contactEl:null,//contact组件DOM
  },
  mutations: {
    // 设置contactEl
    setContact:function(state,el){
      state.contactEl=el
    },
    // 设置joinEl
    setJoin:function(state,el){
      state.joinEl=el
    },
    // 设置aboutEl
    setAbout:function(state,el){
      state.aboutEl=el
    },
    // 设置casesEl
    setCases:function(state,el){
      state.casesEl=el
    },
    // 设置serviceEl
    setService:function(state,el){
      state.serviceEl=el
    },
    //设置headerEl
    setHeader:function(state,el){
      state.headerEl=el
    },
    // 切换tab
    changeTab:function(state,payload){
      var tab=payload.tab
      var transX=payload.transX
      state.activeTab=tab
      state.transX=transX
    },
    // 切换显示导航栏
    toggleShowNav:function(state,type){
      switch(type){
        case 'show':
          if(state.showNav==false){
            state.showNav=true
          }
          break
        case 'hide':
          if(state.showNav==true){
            state.showNav=false
          }
          break
        case 'touch':
        state.showNav=!state.showNav
      }
    }
  }
})
